<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>My Project: Session.h 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">My Project
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.9.8 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','搜索');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function() { init_codefold(0); });
/* @license-end */
</script>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">载入中...</div>
<div class="SRStatus" id="Searching">搜索中...</div>
<div class="SRStatus" id="NoMatches">未找到</div>
</div>
</div>
</div>
</div>

<div class="header">
  <div class="headertitle"><div class="title">Session.h</div></div>
</div><!--header-->
<div class="contents">
<a href="Session_8h.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span> </div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno">   15</span><span class="preprocessor">#pragma once</span></div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno">   16</span> </div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno">   17</span><span class="preprocessor">#include &lt;trantor/utils/Logger.h&gt;</span></div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno">   18</span><span class="preprocessor">#include &lt;map&gt;</span></div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno">   19</span><span class="preprocessor">#include &lt;memory&gt;</span></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno">   20</span><span class="preprocessor">#include &lt;mutex&gt;</span></div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno">   21</span><span class="preprocessor">#include &lt;thread&gt;</span></div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno">   22</span><span class="preprocessor">#include &lt;optional&gt;</span></div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno">   23</span><span class="preprocessor">#include &lt;any&gt;</span></div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno">   24</span> </div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno">   25</span><span class="keyword">namespace </span><a class="code hl_namespace" href="namespacedrogon.html">drogon</a></div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno">   26</span>{</div>
<div class="foldopen" id="foldopen00031" data-start="{" data-end="};">
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html">   31</a></span><span class="keyword">class </span><a class="code hl_class" href="classdrogon_1_1Session.html">Session</a></div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno">   32</span>{</div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno">   33</span>  <span class="keyword">public</span>:</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#a3a0d595286bd764b2d1537776a20cb86">   34</a></span>    <span class="keyword">using </span><a class="code hl_typedef" href="classdrogon_1_1Session.html#a3a0d595286bd764b2d1537776a20cb86">SessionMap</a> = std::map&lt;std::string, std::any&gt;;</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno">   35</span> </div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno">   44</span>    <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="foldopen" id="foldopen00045" data-start="{" data-end="}">
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#a9c0f4cf3ae90dcf3ab056ac31521eae3">   45</a></span>    T <a class="code hl_function" href="classdrogon_1_1Session.html#a9c0f4cf3ae90dcf3ab056ac31521eae3">get</a>(<span class="keyword">const</span> std::string &amp;key)<span class="keyword"> const</span></div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span><span class="keyword">    </span>{</div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno">   47</span>        {</div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno">   48</span>            std::lock_guard&lt;std::mutex&gt; lck(mutex_);</div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno">   49</span>            <span class="keyword">auto</span> it = sessionMap_.find(key);</div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno">   50</span>            <span class="keywordflow">if</span> (it != sessionMap_.end())</div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno">   51</span>            {</div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno">   52</span>                <span class="keywordflow">if</span> (<span class="keyword">typeid</span>(T) == it-&gt;second.type())</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno">   53</span>                {</div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno">   54</span>                    <span class="keywordflow">return</span> *(std::any_cast&lt;T&gt;(&amp;(it-&gt;second)));</div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno">   55</span>                }</div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno">   56</span>                <span class="keywordflow">else</span></div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno">   57</span>                {</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno">   58</span>                    LOG_ERROR &lt;&lt; <span class="stringliteral">&quot;Bad type&quot;</span>;</div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno">   59</span>                }</div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno">   60</span>            }</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno">   61</span>        }</div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno">   62</span>        <span class="keywordflow">return</span> T();</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno">   63</span>    }</div>
</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno">   64</span> </div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno">   73</span>    <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="foldopen" id="foldopen00074" data-start="{" data-end="}">
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#a438151436be4e02e1a38c4afc413482a">   74</a></span>    std::optional&lt;T&gt; <a class="code hl_function" href="classdrogon_1_1Session.html#a438151436be4e02e1a38c4afc413482a">getOptional</a>(<span class="keyword">const</span> std::string &amp;key)<span class="keyword"> const</span></div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno">   75</span><span class="keyword">    </span>{</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span>        {</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno">   77</span>            std::lock_guard&lt;std::mutex&gt; lck(mutex_);</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno">   78</span>            <span class="keyword">auto</span> it = sessionMap_.find(key);</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno">   79</span>            <span class="keywordflow">if</span> (it != sessionMap_.end())</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno">   80</span>            {</div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno">   81</span>                <span class="keywordflow">if</span> (<span class="keyword">typeid</span>(T) == it-&gt;second.type())</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno">   82</span>                {</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno">   83</span>                    <span class="keywordflow">return</span> *(std::any_cast&lt;T&gt;(&amp;(it-&gt;second)));</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno">   84</span>                }</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno">   85</span>                <span class="keywordflow">else</span></div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno">   86</span>                {</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno">   87</span>                    LOG_ERROR &lt;&lt; <span class="stringliteral">&quot;Bad type&quot;</span>;</div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno">   88</span>                }</div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno">   89</span>            }</div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno">   90</span>        }</div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno">   91</span>        <span class="keywordflow">return</span> std::nullopt;</div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno">   92</span>    }</div>
</div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno">   93</span> </div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno">  107</span>    <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T, <span class="keyword">typename</span> Callable&gt;</div>
<div class="foldopen" id="foldopen00108" data-start="{" data-end="}">
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#a4799c04fbeb434828d81f8e66886b187">  108</a></span>    <span class="keywordtype">void</span> <a class="code hl_function" href="classdrogon_1_1Session.html#a4799c04fbeb434828d81f8e66886b187">modify</a>(<span class="keyword">const</span> std::string &amp;key, Callable &amp;&amp;handler)</div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno">  109</span>    {</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno">  110</span>        std::lock_guard&lt;std::mutex&gt; lck(mutex_);</div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno">  111</span>        <span class="keyword">auto</span> it = sessionMap_.find(key);</div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno">  112</span>        <span class="keywordflow">if</span> (it != sessionMap_.end())</div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno">  113</span>        {</div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno">  114</span>            <span class="keywordflow">if</span> (<span class="keyword">typeid</span>(T) == it-&gt;second.type())</div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno">  115</span>            {</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno">  116</span>                handler(*(std::any_cast&lt;T&gt;(&amp;(it-&gt;second))));</div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno">  117</span>            }</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno">  118</span>            <span class="keywordflow">else</span></div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno">  119</span>            {</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno">  120</span>                LOG_ERROR &lt;&lt; <span class="stringliteral">&quot;Bad type&quot;</span>;</div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno">  121</span>            }</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno">  122</span>        }</div>
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno">  123</span>        <span class="keywordflow">else</span></div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno">  124</span>        {</div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno">  125</span>            <span class="keyword">auto</span> item = T();</div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno">  126</span>            handler(item);</div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno">  127</span>            sessionMap_.insert(std::make_pair(key, std::any(std::move(item))));</div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno">  128</span>        }</div>
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno">  129</span>    }</div>
</div>
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno">  130</span> </div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno">  140</span>    <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Callable&gt;</div>
<div class="foldopen" id="foldopen00141" data-start="{" data-end="}">
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#af586a180925de1ec0af28ec7ce029e8b">  141</a></span>    <span class="keywordtype">void</span> <a class="code hl_function" href="classdrogon_1_1Session.html#af586a180925de1ec0af28ec7ce029e8b">modify</a>(Callable &amp;&amp;handler)</div>
<div class="line"><a id="l00142" name="l00142"></a><span class="lineno">  142</span>    {</div>
<div class="line"><a id="l00143" name="l00143"></a><span class="lineno">  143</span>        std::lock_guard&lt;std::mutex&gt; lck(mutex_);</div>
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno">  144</span>        handler(sessionMap_);</div>
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno">  145</span>    }</div>
</div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno">  146</span> </div>
<div class="foldopen" id="foldopen00155" data-start="{" data-end="}">
<div class="line"><a id="l00155" name="l00155"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#a7b1db4bd0e469dc5962214ac51526966">  155</a></span>    <span class="keywordtype">void</span> <a class="code hl_function" href="classdrogon_1_1Session.html#a7b1db4bd0e469dc5962214ac51526966">insert</a>(<span class="keyword">const</span> std::string &amp;key, <span class="keyword">const</span> std::any &amp;obj)</div>
<div class="line"><a id="l00156" name="l00156"></a><span class="lineno">  156</span>    {</div>
<div class="line"><a id="l00157" name="l00157"></a><span class="lineno">  157</span>        std::lock_guard&lt;std::mutex&gt; lck(mutex_);</div>
<div class="line"><a id="l00158" name="l00158"></a><span class="lineno">  158</span>        sessionMap_.insert(std::make_pair(key, obj));</div>
<div class="line"><a id="l00159" name="l00159"></a><span class="lineno">  159</span>    }</div>
</div>
<div class="line"><a id="l00160" name="l00160"></a><span class="lineno">  160</span> </div>
<div class="foldopen" id="foldopen00169" data-start="{" data-end="}">
<div class="line"><a id="l00169" name="l00169"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#ab4326b1894f420e2553b08af43644649">  169</a></span>    <span class="keywordtype">void</span> <a class="code hl_function" href="classdrogon_1_1Session.html#ab4326b1894f420e2553b08af43644649">insert</a>(<span class="keyword">const</span> std::string &amp;key, std::any &amp;&amp;obj)</div>
<div class="line"><a id="l00170" name="l00170"></a><span class="lineno">  170</span>    {</div>
<div class="line"><a id="l00171" name="l00171"></a><span class="lineno">  171</span>        std::lock_guard&lt;std::mutex&gt; lck(mutex_);</div>
<div class="line"><a id="l00172" name="l00172"></a><span class="lineno">  172</span>        sessionMap_.insert(std::make_pair(key, std::move(obj)));</div>
<div class="line"><a id="l00173" name="l00173"></a><span class="lineno">  173</span>    }</div>
</div>
<div class="line"><a id="l00174" name="l00174"></a><span class="lineno">  174</span> </div>
<div class="foldopen" id="foldopen00178" data-start="{" data-end="}">
<div class="line"><a id="l00178" name="l00178"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#afb8428bfc7f7e8f72ba8b12ea799e700">  178</a></span>    <span class="keywordtype">void</span> <a class="code hl_function" href="classdrogon_1_1Session.html#afb8428bfc7f7e8f72ba8b12ea799e700">erase</a>(<span class="keyword">const</span> std::string &amp;key)</div>
<div class="line"><a id="l00179" name="l00179"></a><span class="lineno">  179</span>    {</div>
<div class="line"><a id="l00180" name="l00180"></a><span class="lineno">  180</span>        std::lock_guard&lt;std::mutex&gt; lck(mutex_);</div>
<div class="line"><a id="l00181" name="l00181"></a><span class="lineno">  181</span>        sessionMap_.erase(key);</div>
<div class="line"><a id="l00182" name="l00182"></a><span class="lineno">  182</span>    }</div>
</div>
<div class="line"><a id="l00183" name="l00183"></a><span class="lineno">  183</span> </div>
<div class="foldopen" id="foldopen00187" data-start="{" data-end="}">
<div class="line"><a id="l00187" name="l00187"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#add7381f0cd360e9c17a90cf08f04fbab">  187</a></span>    <span class="keywordtype">bool</span> <a class="code hl_function" href="classdrogon_1_1Session.html#add7381f0cd360e9c17a90cf08f04fbab">find</a>(<span class="keyword">const</span> std::string &amp;key)</div>
<div class="line"><a id="l00188" name="l00188"></a><span class="lineno">  188</span>    {</div>
<div class="line"><a id="l00189" name="l00189"></a><span class="lineno">  189</span>        std::lock_guard&lt;std::mutex&gt; lck(mutex_);</div>
<div class="line"><a id="l00190" name="l00190"></a><span class="lineno">  190</span>        <span class="keywordflow">if</span> (sessionMap_.find(key) == sessionMap_.end())</div>
<div class="line"><a id="l00191" name="l00191"></a><span class="lineno">  191</span>        {</div>
<div class="line"><a id="l00192" name="l00192"></a><span class="lineno">  192</span>            <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a id="l00193" name="l00193"></a><span class="lineno">  193</span>        }</div>
<div class="line"><a id="l00194" name="l00194"></a><span class="lineno">  194</span>        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a id="l00195" name="l00195"></a><span class="lineno">  195</span>    }</div>
</div>
<div class="line"><a id="l00196" name="l00196"></a><span class="lineno">  196</span> </div>
<div class="foldopen" id="foldopen00200" data-start="{" data-end="}">
<div class="line"><a id="l00200" name="l00200"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#a0568aea6589ac3acffc248eb9c2dcddc">  200</a></span>    <span class="keywordtype">void</span> <a class="code hl_function" href="classdrogon_1_1Session.html#a0568aea6589ac3acffc248eb9c2dcddc">clear</a>()</div>
<div class="line"><a id="l00201" name="l00201"></a><span class="lineno">  201</span>    {</div>
<div class="line"><a id="l00202" name="l00202"></a><span class="lineno">  202</span>        std::lock_guard&lt;std::mutex&gt; lck(mutex_);</div>
<div class="line"><a id="l00203" name="l00203"></a><span class="lineno">  203</span>        sessionMap_.clear();</div>
<div class="line"><a id="l00204" name="l00204"></a><span class="lineno">  204</span>    }</div>
</div>
<div class="line"><a id="l00205" name="l00205"></a><span class="lineno">  205</span> </div>
<div class="foldopen" id="foldopen00209" data-start="{" data-end="}">
<div class="line"><a id="l00209" name="l00209"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#a5cc88d9ac3f6fdd497609f5f3d587bdc">  209</a></span>    std::string <a class="code hl_function" href="classdrogon_1_1Session.html#a5cc88d9ac3f6fdd497609f5f3d587bdc">sessionId</a>()<span class="keyword"> const</span></div>
<div class="line"><a id="l00210" name="l00210"></a><span class="lineno">  210</span><span class="keyword">    </span>{</div>
<div class="line"><a id="l00211" name="l00211"></a><span class="lineno">  211</span>        std::lock_guard&lt;std::mutex&gt; lck(mutex_);</div>
<div class="line"><a id="l00212" name="l00212"></a><span class="lineno">  212</span>        <span class="keywordflow">return</span> sessionId_;</div>
<div class="line"><a id="l00213" name="l00213"></a><span class="lineno">  213</span>    }</div>
</div>
<div class="line"><a id="l00214" name="l00214"></a><span class="lineno">  214</span> </div>
<div class="foldopen" id="foldopen00220" data-start="{" data-end="}">
<div class="line"><a id="l00220" name="l00220"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#a96e4bd48684d080b5b39371517f5f0c1">  220</a></span>    <span class="keywordtype">void</span> <a class="code hl_function" href="classdrogon_1_1Session.html#a96e4bd48684d080b5b39371517f5f0c1">changeSessionIdToClient</a>()</div>
<div class="line"><a id="l00221" name="l00221"></a><span class="lineno">  221</span>    {</div>
<div class="line"><a id="l00222" name="l00222"></a><span class="lineno">  222</span>        needToChange_ = <span class="keyword">true</span>;</div>
<div class="line"><a id="l00223" name="l00223"></a><span class="lineno">  223</span>        needToSet_ = <span class="keyword">true</span>;</div>
<div class="line"><a id="l00224" name="l00224"></a><span class="lineno">  224</span>    }</div>
</div>
<div class="line"><a id="l00225" name="l00225"></a><span class="lineno">  225</span> </div>
<div class="line"><a id="l00226" name="l00226"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#ae6c5ce8ba0cb1db8cb9f4a6b8947b80a">  226</a></span>    <a class="code hl_function" href="classdrogon_1_1Session.html#ae6c5ce8ba0cb1db8cb9f4a6b8947b80a">Session</a>() = <span class="keyword">delete</span>;</div>
<div class="line"><a id="l00227" name="l00227"></a><span class="lineno">  227</span> </div>
<div class="line"><a id="l00228" name="l00228"></a><span class="lineno">  228</span>  <span class="keyword">private</span>:</div>
<div class="line"><a id="l00229" name="l00229"></a><span class="lineno">  229</span>    <a class="code hl_typedef" href="classdrogon_1_1Session.html#a3a0d595286bd764b2d1537776a20cb86">SessionMap</a> sessionMap_;</div>
<div class="line"><a id="l00230" name="l00230"></a><span class="lineno">  230</span>    <span class="keyword">mutable</span> std::mutex mutex_;</div>
<div class="line"><a id="l00231" name="l00231"></a><span class="lineno">  231</span>    std::string sessionId_;</div>
<div class="line"><a id="l00232" name="l00232"></a><span class="lineno">  232</span>    <span class="keywordtype">bool</span> needToSet_{<span class="keyword">false</span>};</div>
<div class="line"><a id="l00233" name="l00233"></a><span class="lineno">  233</span>    <span class="keywordtype">bool</span> needToChange_{<span class="keyword">false</span>};</div>
<div class="line"><a id="l00234" name="l00234"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#ac01f2e55f53ab751ca060dd59189c930">  234</a></span>    <span class="keyword">friend</span> <span class="keyword">class </span><a class="code hl_friend" href="classdrogon_1_1Session.html#ac01f2e55f53ab751ca060dd59189c930">SessionManager</a>;</div>
<div class="line"><a id="l00235" name="l00235"></a><span class="lineno"><a class="line" href="classdrogon_1_1Session.html#ac6432db4350125a5623ccfe713085fd5">  235</a></span>    <span class="keyword">friend</span> <span class="keyword">class </span><a class="code hl_friend" href="classdrogon_1_1Session.html#ac6432db4350125a5623ccfe713085fd5">HttpAppFrameworkImpl</a>;</div>
<div class="line"><a id="l00236" name="l00236"></a><span class="lineno">  236</span> </div>
<div class="line"><a id="l00240" name="l00240"></a><span class="lineno">  240</span>    <a class="code hl_function" href="classdrogon_1_1Session.html#ae6c5ce8ba0cb1db8cb9f4a6b8947b80a">Session</a>(<span class="keyword">const</span> std::string &amp;<span class="keywordtype">id</span>, <span class="keywordtype">bool</span> needToSet)</div>
<div class="line"><a id="l00241" name="l00241"></a><span class="lineno">  241</span>        : sessionId_(id), needToSet_(needToSet)</div>
<div class="line"><a id="l00242" name="l00242"></a><span class="lineno">  242</span>    {</div>
<div class="line"><a id="l00243" name="l00243"></a><span class="lineno">  243</span>    }</div>
<div class="line"><a id="l00244" name="l00244"></a><span class="lineno">  244</span> </div>
<div class="line"><a id="l00248" name="l00248"></a><span class="lineno">  248</span>    <span class="keywordtype">void</span> hasSet()</div>
<div class="line"><a id="l00249" name="l00249"></a><span class="lineno">  249</span>    {</div>
<div class="line"><a id="l00250" name="l00250"></a><span class="lineno">  250</span>        needToSet_ = <span class="keyword">false</span>;</div>
<div class="line"><a id="l00251" name="l00251"></a><span class="lineno">  251</span>    }</div>
<div class="line"><a id="l00252" name="l00252"></a><span class="lineno">  252</span> </div>
<div class="line"><a id="l00257" name="l00257"></a><span class="lineno">  257</span>    <span class="keywordtype">bool</span> needToChangeSessionId()<span class="keyword"> const</span></div>
<div class="line"><a id="l00258" name="l00258"></a><span class="lineno">  258</span><span class="keyword">    </span>{</div>
<div class="line"><a id="l00259" name="l00259"></a><span class="lineno">  259</span>        <span class="keywordflow">return</span> needToChange_;</div>
<div class="line"><a id="l00260" name="l00260"></a><span class="lineno">  260</span>    }</div>
<div class="line"><a id="l00261" name="l00261"></a><span class="lineno">  261</span> </div>
<div class="line"><a id="l00266" name="l00266"></a><span class="lineno">  266</span>    <span class="keywordtype">bool</span> needSetToClient()<span class="keyword"> const</span></div>
<div class="line"><a id="l00267" name="l00267"></a><span class="lineno">  267</span><span class="keyword">    </span>{</div>
<div class="line"><a id="l00268" name="l00268"></a><span class="lineno">  268</span>        <span class="keywordflow">return</span> needToSet_;</div>
<div class="line"><a id="l00269" name="l00269"></a><span class="lineno">  269</span>    }</div>
<div class="line"><a id="l00270" name="l00270"></a><span class="lineno">  270</span> </div>
<div class="line"><a id="l00271" name="l00271"></a><span class="lineno">  271</span>    <span class="keywordtype">void</span> setSessionId(<span class="keyword">const</span> std::string &amp;<span class="keywordtype">id</span>)</div>
<div class="line"><a id="l00272" name="l00272"></a><span class="lineno">  272</span>    {</div>
<div class="line"><a id="l00273" name="l00273"></a><span class="lineno">  273</span>        std::lock_guard&lt;std::mutex&gt; lck(mutex_);</div>
<div class="line"><a id="l00274" name="l00274"></a><span class="lineno">  274</span>        sessionId_ = id;</div>
<div class="line"><a id="l00275" name="l00275"></a><span class="lineno">  275</span>        needToChange_ = <span class="keyword">false</span>;</div>
<div class="line"><a id="l00276" name="l00276"></a><span class="lineno">  276</span>    }</div>
<div class="line"><a id="l00277" name="l00277"></a><span class="lineno">  277</span>};</div>
</div>
<div class="line"><a id="l00278" name="l00278"></a><span class="lineno">  278</span> </div>
<div class="line"><a id="l00279" name="l00279"></a><span class="lineno"><a class="line" href="namespacedrogon.html#af0ccaa26ab9bac38fbfa3caf29a9d970">  279</a></span><span class="keyword">using </span><a class="code hl_typedef" href="namespacedrogon.html#af0ccaa26ab9bac38fbfa3caf29a9d970">SessionPtr</a> = std::shared_ptr&lt;Session&gt;;</div>
<div class="line"><a id="l00280" name="l00280"></a><span class="lineno">  280</span> </div>
<div class="line"><a id="l00281" name="l00281"></a><span class="lineno">  281</span>}  <span class="comment">// namespace drogon</span></div>
<div class="ttc" id="aclassdrogon_1_1Session_html"><div class="ttname"><a href="classdrogon_1_1Session.html">drogon::Session</a></div><div class="ttdoc">This class represents a session stored in the framework. One can get or set any type of data to a ses...</div><div class="ttdef"><b>Definition</b> Session.h:32</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_a0568aea6589ac3acffc248eb9c2dcddc"><div class="ttname"><a href="classdrogon_1_1Session.html#a0568aea6589ac3acffc248eb9c2dcddc">drogon::Session::clear</a></div><div class="ttdeci">void clear()</div><div class="ttdoc">Clear all data in the session.</div><div class="ttdef"><b>Definition</b> Session.h:200</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_a3a0d595286bd764b2d1537776a20cb86"><div class="ttname"><a href="classdrogon_1_1Session.html#a3a0d595286bd764b2d1537776a20cb86">drogon::Session::SessionMap</a></div><div class="ttdeci">std::map&lt; std::string, std::any &gt; SessionMap</div><div class="ttdef"><b>Definition</b> Session.h:34</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_a438151436be4e02e1a38c4afc413482a"><div class="ttname"><a href="classdrogon_1_1Session.html#a438151436be4e02e1a38c4afc413482a">drogon::Session::getOptional</a></div><div class="ttdeci">std::optional&lt; T &gt; getOptional(const std::string &amp;key) const</div><div class="ttdoc">Get the data identified by the key parameter and return an optional object that wraps the data.</div><div class="ttdef"><b>Definition</b> Session.h:74</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_a4799c04fbeb434828d81f8e66886b187"><div class="ttname"><a href="classdrogon_1_1Session.html#a4799c04fbeb434828d81f8e66886b187">drogon::Session::modify</a></div><div class="ttdeci">void modify(const std::string &amp;key, Callable &amp;&amp;handler)</div><div class="ttdoc">Modify or visit the data identified by the key parameter.</div><div class="ttdef"><b>Definition</b> Session.h:108</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_a5cc88d9ac3f6fdd497609f5f3d587bdc"><div class="ttname"><a href="classdrogon_1_1Session.html#a5cc88d9ac3f6fdd497609f5f3d587bdc">drogon::Session::sessionId</a></div><div class="ttdeci">std::string sessionId() const</div><div class="ttdoc">Get the session ID of the current session.</div><div class="ttdef"><b>Definition</b> Session.h:209</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_a7b1db4bd0e469dc5962214ac51526966"><div class="ttname"><a href="classdrogon_1_1Session.html#a7b1db4bd0e469dc5962214ac51526966">drogon::Session::insert</a></div><div class="ttdeci">void insert(const std::string &amp;key, const std::any &amp;obj)</div><div class="ttdoc">Insert a key-value pair</div><div class="ttdef"><b>Definition</b> Session.h:155</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_a96e4bd48684d080b5b39371517f5f0c1"><div class="ttname"><a href="classdrogon_1_1Session.html#a96e4bd48684d080b5b39371517f5f0c1">drogon::Session::changeSessionIdToClient</a></div><div class="ttdeci">void changeSessionIdToClient()</div><div class="ttdoc">Let the framework create a new session ID for this session and set it to the client.</div><div class="ttdef"><b>Definition</b> Session.h:220</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_a9c0f4cf3ae90dcf3ab056ac31521eae3"><div class="ttname"><a href="classdrogon_1_1Session.html#a9c0f4cf3ae90dcf3ab056ac31521eae3">drogon::Session::get</a></div><div class="ttdeci">T get(const std::string &amp;key) const</div><div class="ttdoc">Get the data identified by the key parameter.</div><div class="ttdef"><b>Definition</b> Session.h:45</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_ab4326b1894f420e2553b08af43644649"><div class="ttname"><a href="classdrogon_1_1Session.html#ab4326b1894f420e2553b08af43644649">drogon::Session::insert</a></div><div class="ttdeci">void insert(const std::string &amp;key, std::any &amp;&amp;obj)</div><div class="ttdoc">Insert a key-value pair</div><div class="ttdef"><b>Definition</b> Session.h:169</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_ac01f2e55f53ab751ca060dd59189c930"><div class="ttname"><a href="classdrogon_1_1Session.html#ac01f2e55f53ab751ca060dd59189c930">drogon::Session::SessionManager</a></div><div class="ttdeci">friend class SessionManager</div><div class="ttdef"><b>Definition</b> Session.h:234</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_ac6432db4350125a5623ccfe713085fd5"><div class="ttname"><a href="classdrogon_1_1Session.html#ac6432db4350125a5623ccfe713085fd5">drogon::Session::HttpAppFrameworkImpl</a></div><div class="ttdeci">friend class HttpAppFrameworkImpl</div><div class="ttdef"><b>Definition</b> Session.h:235</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_add7381f0cd360e9c17a90cf08f04fbab"><div class="ttname"><a href="classdrogon_1_1Session.html#add7381f0cd360e9c17a90cf08f04fbab">drogon::Session::find</a></div><div class="ttdeci">bool find(const std::string &amp;key)</div><div class="ttdoc">Return true if the data identified by the key exists.</div><div class="ttdef"><b>Definition</b> Session.h:187</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_ae6c5ce8ba0cb1db8cb9f4a6b8947b80a"><div class="ttname"><a href="classdrogon_1_1Session.html#ae6c5ce8ba0cb1db8cb9f4a6b8947b80a">drogon::Session::Session</a></div><div class="ttdeci">Session()=delete</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_af586a180925de1ec0af28ec7ce029e8b"><div class="ttname"><a href="classdrogon_1_1Session.html#af586a180925de1ec0af28ec7ce029e8b">drogon::Session::modify</a></div><div class="ttdeci">void modify(Callable &amp;&amp;handler)</div><div class="ttdoc">Modify or visit the session data.</div><div class="ttdef"><b>Definition</b> Session.h:141</div></div>
<div class="ttc" id="aclassdrogon_1_1Session_html_afb8428bfc7f7e8f72ba8b12ea799e700"><div class="ttname"><a href="classdrogon_1_1Session.html#afb8428bfc7f7e8f72ba8b12ea799e700">drogon::Session::erase</a></div><div class="ttdeci">void erase(const std::string &amp;key)</div><div class="ttdoc">Erase the data identified by the given key.</div><div class="ttdef"><b>Definition</b> Session.h:178</div></div>
<div class="ttc" id="anamespacedrogon_html"><div class="ttname"><a href="namespacedrogon.html">drogon</a></div><div class="ttdoc">Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...</div><div class="ttdef"><b>Definition</b> Attribute.h:23</div></div>
<div class="ttc" id="anamespacedrogon_html_af0ccaa26ab9bac38fbfa3caf29a9d970"><div class="ttname"><a href="namespacedrogon.html#af0ccaa26ab9bac38fbfa3caf29a9d970">drogon::SessionPtr</a></div><div class="ttdeci">std::shared_ptr&lt; Session &gt; SessionPtr</div><div class="ttdef"><b>Definition</b> Session.h:279</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8
</small></address>
</body>
</html>
